package cmdb

import (
	"github.com/gogf/gf/frame/g"
)

func GetStorageList() (interface{}, int) {
	storage, err := g.DB().Table("cmdb_storagemachine").All()

	count := len(storage)
	if err != nil {
		panic(err)
	}
	return storage, count
}

func StorageUpdateData(i interface{}, id interface{}) {
	// UPDATE `cmdb_storagemachine` SET `ip`='aaa' WHERE ip='bbb'
	_, err := g.DB().Table("cmdb_storagemachine").Data(i).Where("id", id).Update()
	if err != nil {
		panic(err)
	}
}

func StorageDelData(id interface{}) {
	// DELETE FROM `cmdb_storagemachine` WHERE id=10
	_, err := g.DB().Table("cmdb_storagemachine").Where("id", id).Delete()
	if err != nil {
		panic(err)
	}
}

func StorageDelAll(id interface{}) {
	// Where("status IN (?)", g.Slice{1,2,3})
	_, err := g.DB().Table("cmdb_storagemachine").Where("id IN (?)", id).Delete()
	if err != nil {
		panic(err)
	}
}

func StorageAddData(i interface{}) {
	// INSERT INTO `user`(`cmdb_storagemachine`) VALUES('xx')
	_, err := g.DB().Table("cmdb_storagemachine").Data(i).Insert()
	if err != nil {
		panic(err)
	}
}
